package patrol.mobile.com.mobilepatrol.activity.office;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.AdviceDetailBean;
import patrol.mobile.com.mobilepatrol.manager.UserManager;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;
import patrol.mobile.com.mobilepatrol.utils.Constants;
import patrol.mobile.com.mobilepatrol.utils.GsonUtil;
import patrol.mobile.com.mobilepatrol.utils.SPUtils;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack2;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;

public class AdviceDetail1Activity extends BaseActivity {

    private static final String TAG = "ADVICEDETAIL";
    @BindView(R.id.et_title)
    TextView etTitle;
    @BindView(R.id.et_content)
    TextView etContent;
    @BindView(R.id.et_huifu)
    TextView etHuifu;
    private static final String ADVICE_ID = "ADVICE_ID";
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private String id;

    public static void show(Context context, String id) {
        Intent intent = new Intent(context, AdviceDetail1Activity.class);
        intent.putExtra(ADVICE_ID, id);
        context.startActivity(intent);
    }

    @Override
    public void initTitle() {
        super.initTitle();
        iv_back.setImageResource(R.mipmap.up_white);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CommonUtil.exitActivityAndBackAnim(AdviceDetail1Activity.this, true);
            }
        });
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText("意见详情");
        recyclerView.setLayoutManager(new GridLayoutManager(this,3));
    }


    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_advice_detail1;
    }

    @Override
    public void initData() {
        super.initData();
        id = getIntent().getStringExtra(ADVICE_ID);
        requestData();
        String current_id = (String) SPUtils.get(Constants.current_id, "");
        Log.i(TAG, "requestData: " + current_id);
        String username = UserManager.getUser(current_id).username;
        String bmcode = UserManager.getUser(current_id).bmcode;
        String bmname = UserManager.getUser(current_id).bmname;
        String pw = UserManager.getUser(current_id).pw;
        String ryid = UserManager.getUser(current_id).ryid;
        String ryname = UserManager.getUser(current_id).ryname;
        String orgName = UserManager.getUser(current_id).orgName;
        String org_No = UserManager.getUser(current_id).org_No;
        String orgtype = UserManager.getUser(current_id).orgtype;

        Log.i(TAG, "requestData: " + username + "---" + bmcode + "---" + bmname + "---" + pw + "---" + ryid + "---" + ryname + "---" + orgName + "---" + org_No + "---" + orgtype + "---");

    }

    private void requestData() {

        HttpSender sender = new HttpSender(this, baseUrl, Urls.ADVICE_ENTITY);
        HashMap<String, String> map = new HashMap<>();
        map.put("id", id);
        sender.requestPost(map, new HttpCallBack2(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response, String attachList) {
                AdviceDetailBean adviceDetailBean = GsonUtil.GsonToBean(response, AdviceDetailBean.class);
                etTitle.setText(adviceDetailBean.getTitle());
                etContent.setText(adviceDetailBean.getContent());
                etHuifu.setText(adviceDetailBean.getReplayContent());
            }
        });
    }

    @Override
    public void setListener() {

    }

}
